//
//  ViewController.m
//  LZYTabbarController
//
//  Created by 刘宇 on 2018/5/3.
//  Copyright © 2018年 瀚宇悟道. All rights reserved.
//

#import "ViewController.h"
#import "UIButton+HitControl.h"
#import "LZYTabBarViewController.h"
#import "LZYTabBarConfig.h"
#import "UIView+LZY.h"

@interface ViewController ()
/** dataArrM */
@property (nonatomic, strong) NSMutableArray *dataArrM;
/** 关闭按钮 */
@property (nonatomic, strong) UIButton *closeBtn;
/** tabbar */
@property (nonatomic, strong) LZYTabBarViewController *tabBarVc;
/** 强引用 */
@property (nonatomic, strong) ViewController *vc;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    //初始化配置信息
    LZYTabBarConfig *config = [LZYTabBarConfig shareConfig];
    [config configNormal];
    NSMutableArray *titleArr = [NSMutableArray arrayWithObjects:@"首页",@"热点",@"doki",@"圈子", nil];
    NSMutableArray *imageNormalArr = [NSMutableArray arrayWithObjects:@"tab1_nor",@"tab2_nor",@"tab3_nor",@"tab4_nor", nil];
    NSMutableArray *imageSelectedArr = [NSMutableArray arrayWithObjects:@"tab1_sel",@"tab2_sel",@"tab3_sel",@"tab4_sel", nil];
    NSMutableArray *controllersArr = [NSMutableArray array];
    for (int i = 0; i < titleArr.count; i++) {
        if (i == 0) {
            self.vc = [[ViewController alloc] init];
            self.vc.view.backgroundColor = [UIColor colorWithHexString:@"#f5f5f5"];
            [controllersArr addObject:self.vc];
        } else {
            UIViewController *vc = [[UIViewController alloc] init];
            vc.view.backgroundColor = kRandomColor;
            [controllersArr addObject:vc];
        }
    }
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [config showNumberBadgeValue:@"6" AtIndex:3];
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.y = -30;
        //btn.imageEdgeInsets = UIEdgeInsetsMake(-30, 0, 0, 0);
        //btn.hitFrame = CGRectMake(0, -20, 50, 50);//点击整个红色View响应事件
        [btn setImage:[UIImage imageNamed:@"add"] forState:UIControlStateNormal];
        [config addCustomBtn:btn AtIndex:2 BtnClickBlock:^(UIButton *btn, NSInteger index) {
            NSLog(@"点击了我");
            UIViewController *VC = controllersArr[0];
            UIViewController *vc = [[UIViewController alloc] init];
            vc.view.backgroundColor = [UIColor orangeColor];
            [VC presentViewController:vc animated:YES completion:nil];
        }];
    });
    
    self.tabBarVc = [[LZYTabBarViewController alloc] initWithTabBarControllers:controllersArr NorImageArr:imageNormalArr SelImageArr:imageSelectedArr TitleArr:titleArr Config:config];
    
    [self presentViewController:self.tabBarVc animated:YES completion:nil];
    
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end

